<template>
	<view class="bind" v-if="loadStatus">
		<view class="tips">您的好友邀请你共享他账户<text class="text-red">【{{account_name}}】</text>的账本记录，是否同意？如果同意，请填写备注名称后点击确认.
		</view>
		<view class="remark">
			<u--input v-model="remark" placeholder="请输入备注名称"></u--input>
		</view>
		<button class="bg-theme text-white" @tap="onSubmit">同意</button>
	</view>
</template>

<script>
	import shareModel from '../../models/ShareModel'

	export default {
		data() {
			return {
				loadStatus: false,
				id: '',
				account_name: '',
				remark: ''
			}
		},
		async onLoad(options) {
			this.id = options.id
			uni.showLoading({
				mask: true
			})
			await this.getDetail()
			this.loadStatus = true
		},
		methods: {
			async getDetail() {
				const res = await shareModel.detail(this.id)
				uni.hideLoading()
				if (res.code == 200) {
					this.account_name = res.data
				} else {

					this.$base.alert(res.msg, () => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					})

				}
			},
			onSubmit() {
				if (!this.remark) {
					this.$base.msg('请填写备注')
					return
				}

				uni.showLoading({
					mask: true
				})
				shareModel.join(this.id, this.remark).then(res => {
					uni.hideLoading()
					this.$base.alert(res.msg, () => {
						if (res.code == 200) {
							uni.switchTab({
								url: '/pages/index/index'
							})
						}
					})

				})
			}
		}
	}
</script>

<style scoped lang="less">
	.bind {
		padding: 20rpx 40rpx;

		.remark {
			margin: 40rpx 0;
		}
	}
</style>